package com.appspot.abcensys.shared;

import java.util.ArrayList;

import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Image;

/**
 * MenuItem
 * 
 * Word gebruikt om het menu te bouwen
 * 
 * @author Hugo Zonderland
 *
 */
public class MenuItem
{
	private String title;
	private Command cmd;
	private ArrayList<Integer> types;
	private Image img;

	/**
	 * Constructor
	 */
	public MenuItem() {
		this.types = new ArrayList<Integer>();
	}

	/**
	 * Constructor
	 */
	public MenuItem(String title, Command cmd) {
		this.types = new ArrayList<Integer>();
		this.title = title;
		this.setCmd(cmd);
	}
	
	/**
	 * @param text the text to set
	 */
	public void setText(String text) {
		this.title = text;
	}
	
	/**
	 * @param title the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}
	
	/**
	 * @return the title
	 */
	public String getTitle() {
		return this.title;
	}

	/**
	 * @param rollen the rollen to set
	 */
	public void setTypes(ArrayList<Integer> types) {
		this.types = types;
	}

	/**
	 * @return the rollen
	 */
	public ArrayList<Integer> getTypes() {
		return types;
	}
	
	/**
	 * Voegt een rol toe voor dit menu item.
	 * @param rol
	 */
	public void addType(Integer type) {
		if(!this.types.contains(type)) {
			this.types.add(type);
		}
	}
	
	/**
	 * Controleert of een bepaalde rol in de rollenset zit.
	 * @param rollen
	 * @return TRUE indien access, FALSE indien verboden.
	 */
	public boolean allowed(Integer type) {
		if(this.types.size() == 0) {
			return true;
		}
		
		if(this.types.contains(type)) {
			return true;
		}
		
		return false;
	}

	/**
	 * @return the cmd
	 */
	public Command getCmd() {
		return cmd;
	}

	/**
	 * @param cmd the cmd to set
	 */
	public void setCmd(Command cmd) {
		this.cmd = cmd;
	}

	/**
	 * @return the img
	 */
	public Image getImg() {
		return img;
	}

	/**
	 * @param img the img to set
	 */
	public void setImg(Image img) {
		this.img = img;
	}
}
